﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using BestLifePOS_Core.DomainObjects;
using BestLifePOS_Core.Data.Core;
using BestLifePOS_Core.Exceptions.DataBase;
using System.Data;

namespace BestLifePOS_Core.Data.Commands
{
    class BestLifeGetAllBankDataAction : BestLifeDataAction<List<Bank>>
    {

        //private int GvBankId;

        public BestLifeGetAllBankDataAction()
        {
            //GvBankId = PBankId;
        }

        public override List<Bank> Body(SqlConnection PConn)
        {
            try
            {
                List<Bank> LvList = new List<Bank>();
                //string LvQuery = ""; //Sql Query //when using Sql query intead of SP
                //SqlCommand LvCommand = new SqlCommand(LvQuery, PConn);//when using Sql query intead of SP

                SqlCommand LvCommand = new SqlCommand();

                LvCommand.CommandType = CommandType.StoredProcedure;
                LvCommand.CommandText = "dbo.GetBankDetails";

                //LvCommand.Parameters.Add(new SqlParameter("@xxxxx", GvBankId));//when passing parameters to the SP
                ////SqlParameter LvBankId = new SqlParameter("BankID", GvBankId);//when using SQL qeury and parameter passing
                //LvCommand.Parameters.Add(LvBankId);//adding paramete to the Command
                SqlDataReader LvReader = LvCommand.ExecuteReader();
                while (LvReader.Read())
                {
                    Bank LvBank = new Bank();
                    LvBank.Bank_Name = LvReader.GetValue(0).ToString();

                    LvList.Add(LvBank);
                }
                return LvList;
            }
            catch (BestlifeDatabaseException e)
            {
                throw new BestlifeDatabaseException(e);
            }
        }
    }
}
